home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 262 / SOMC Family Forum 262.iso / Xtras / ScriptOMatic Lite.Dxr / 00012_ScriptFormatter.ls < prev    next >
Encoding:
Text File  |  1997-04-30  |  8.0 KB  |  165 lines

  1. property pScriptMember, pCastLibrary, pColorTable, ancestor
  2. global gScriptOMaticCurrentFormatTable, gScriptOMaticMasterColorTable
  3.  
  4. on new me, scriptMember, castLibrary, scriptText, handlerNamelist
  5.   set the pScriptMember of me to scriptMember
  6.   set the pCastLibrary of me to castLibrary
  7.   set the pColorTable of me to duplicate(gScriptOMaticMasterColorTable)
  8.   set the ancestor of me to new(script "ScriptParser", the pScriptMember of me, the pCastLibrary of me, scriptText, handlerNamelist)
  9.   return me
  10. end
  11.  
  12. on scriptFace faceType
  13.   case the platform starts "M" of
  14.     1:
  15.       case faceType of
  16.         "Monospaced":
  17.           return "Monaco"
  18.         "Proportional":
  19.           return "Times"
  20.       end case
  21.     0:
  22.       case faceType of
  23.         "Monospaced":
  24.           return "Arial"
  25.         "Proportional":
  26.           return "Times New Roman"
  27.       end case
  28.   end case
  29.   return faceType
  30. end
  31.  
  32. on formatScript me
  33.   startFormatToScript(me)
  34.   set styleRunList to [#styles: [#plain], #face: scriptFace("Monospaced"), #size: 9, #Color: [0, 0, 0], #characterRuns: []]
  35.   setaProp(styleRunList, #characterRuns, [[1, 99999]])
  36.   applyFormatToScript(me, styleRunList, "default styles")
  37.   set formatTable to the commentsFormat of gScriptOMaticCurrentFormatTable
  38.   if the activate of formatTable and (count(the pCommentRuns of me) > 0) then
  39.     set Color to getaProp(the pColorTable of me, symbol(the Color of formatTable))
  40.     set style to list(symbol(the style of formatTable))
  41.     set face to scriptFace(the face of formatTable)
  42.     set styleRunList to [#styles: style, #face: face, #size: value(the size of formatTable), #Color: Color, #characterRuns: []]
  43.     setaProp(styleRunList, #characterRuns, the pCommentRuns of me)
  44.     applyFormatToScript(me, styleRunList, "comments")
  45.   end if
  46.   set formatTable to the globalDeclarationsFormat of gScriptOMaticCurrentFormatTable
  47.   if the activate of formatTable and (count(the pGlobalDeclarationRuns of me) > 0) then
  48.     set Color to getaProp(the pColorTable of me, symbol(the Color of formatTable))
  49.     set style to list(symbol(the style of formatTable))
  50.     set face to scriptFace(the face of formatTable)
  51.     set styleRunList to [#styles: style, #face: face, #size: value(the size of formatTable), #Color: Color, #characterRuns: []]
  52.     setaProp(styleRunList, #characterRuns, the pGlobalDeclarationRuns of me)
  53.     applyFormatToScript(me, styleRunList, "global declarations")
  54.   end if
  55.   set formatTable to the propertyDeclarationsFormat of gScriptOMaticCurrentFormatTable
  56.   if the activate of formatTable and (count(the pPropertyDeclarationRuns of me) > 0) then
  57.     set Color to getaProp(the pColorTable of me, symbol(the Color of formatTable))
  58.     set style to list(symbol(the style of formatTable))
  59.     set face to scriptFace(the face of formatTable)
  60.     set styleRunList to [#styles: style, #face: face, #size: value(the size of formatTable), #Color: Color, #characterRuns: []]
  61.     setaProp(styleRunList, #characterRuns, the pPropertyDeclarationRuns of me)
  62.     applyFormatToScript(me, styleRunList, "property declarations")
  63.   end if
  64.   set formatTable to the handlerDeclarationsFormat of gScriptOMaticCurrentFormatTable
  65.   if the activate of formatTable and (count(the pHandlerDeclarationRuns of me) > 0) then
  66.     set Color to getaProp(the pColorTable of me, symbol(the Color of formatTable))
  67.     set style to list(symbol(the style of formatTable))
  68.     set face to scriptFace(the face of formatTable)
  69.     set styleRunList to [#styles: style, #face: face, #size: value(the size of formatTable), #Color: Color, #characterRuns: []]
  70.     setaProp(styleRunList, #characterRuns, the pHandlerDeclarationRuns of me)
  71.     applyFormatToScript(me, styleRunList, "handler declarations")
  72.   end if
  73.   set formatTable to the localDeclarationsFormat of gScriptOMaticCurrentFormatTable
  74.   if the activate of formatTable and (count(the pLocalDeclarationRuns of me) > 0) then
  75.     set Color to getaProp(the pColorTable of me, symbol(the Color of formatTable))
  76.     set style to list(symbol(the style of formatTable))
  77.     set face to scriptFace(the face of formatTable)
  78.     set styleRunList to [#styles: style, #face: face, #size: value(the size of formatTable), #Color: Color, #characterRuns: []]
  79.     setaProp(styleRunList, #characterRuns, the pLocalDeclarationRuns of me)
  80.     applyFormatToScript(me, styleRunList, "local declarations")
  81.   end if
  82.   set formatTable to the globalVariablesFormat of gScriptOMaticCurrentFormatTable
  83.   if the activate of formatTable and (count(the pGlobalVariableRuns of me) > 0) then
  84.     set Color to getaProp(the pColorTable of me, symbol(the Color of formatTable))
  85.     set style to list(symbol(the style of formatTable))
  86.     set face to scriptFace(the face of formatTable)
  87.     set styleRunList to [#styles: style, #face: face, #size: value(the size of formatTable), #Color: Color, #characterRuns: []]
  88.     setaProp(styleRunList, #characterRuns, the pGlobalVariableRuns of me)
  89.     applyFormatToScript(me, styleRunList, "global references")
  90.   end if
  91.   set formatTable to the propertyVariablesFormat of gScriptOMaticCurrentFormatTable
  92.   if the activate of formatTable and (count(the pPropertyVariableRuns of me) > 0) then
  93.     set Color to getaProp(the pColorTable of me, symbol(the Color of formatTable))
  94.     set style to list(symbol(the style of formatTable))
  95.     set face to scriptFace(the face of formatTable)
  96.     set styleRunList to [#styles: style, #face: face, #size: value(the size of formatTable), #Color: Color, #characterRuns: []]
  97.     setaProp(styleRunList, #characterRuns, the pPropertyVariableRuns of me)
  98.     applyFormatToScript(me, styleRunList, "property references")
  99.   end if
  100.   set formatTable to the handlerNamesFormat of gScriptOMaticCurrentFormatTable
  101.   if the activate of formatTable and (count(the pHandlerNameRuns of me) > 0) then
  102.     set Color to getaProp(the pColorTable of me, symbol(the Color of formatTable))
  103.     set style to list(symbol(the style of formatTable))
  104.     set face to scriptFace(the face of formatTable)
  105.     set styleRunList to [#styles: style, #face: face, #size: value(the size of formatTable), #Color: Color, #characterRuns: []]
  106.     setaProp(styleRunList, #characterRuns, the pHandlerNameRuns of me)
  107.     applyFormatToScript(me, styleRunList, "handler references")
  108.   end if
  109.   set formatTable to the localVariablesFormat of gScriptOMaticCurrentFormatTable
  110.   if the activate of formatTable and (count(the pLocalVariableRuns of me) > 0) then
  111.     set Color to getaProp(the pColorTable of me, symbol(the Color of formatTable))
  112.     set style to list(symbol(the style of formatTable))
  113.     set face to scriptFace(the face of formatTable)
  114.     set styleRunList to [#styles: style, #face: face, #size: value(the size of formatTable), #Color: Color, #characterRuns: []]
  115.     setaProp(styleRunList, #characterRuns, the pLocalVariableRuns of me)
  116.     applyFormatToScript(me, styleRunList, "local references")
  117.   end if
  118.   endFormatToScript(me)
  119. end
  120.  
  121. on startFormatToScript me
  122.   tell the stage
  123.     scolUseThisMovie()
  124.   end tell
  125.   tell the stage
  126.     scolUseCastLib(the pCastLibrary of me)
  127.   end tell
  128.   tell the stage
  129.     set scolResult to scolUseMember(the pScriptMember of me)
  130.   end tell
  131.   if scolResult = "OK" then
  132.   else
  133.     alert("Sorry, a fatal error occurred:" && scolResult & RETURN & "when processing member" && the pScriptMember of me && "in castLib" && the pCastLibrary of me)
  134.     closeScriptOMatic()
  135.   end if
  136. end
  137.  
  138. on applyFormatToScript me, styleSpecifications, stylingComment
  139.   tell the stage
  140.     set scolResult to scolSetScriptStyles(styleSpecifications)
  141.   end tell
  142.   if scolResult = "OK" then
  143.     exit
  144.   else
  145.     alert("Sorry, a minor error occurred:" && scolResult & RETURN & "when styling the" && stylingComment && "of member" && the pScriptMember of me && "in castLib" && the pCastLibrary of me)
  146.     exit
  147.   end if
  148. end
  149.  
  150. on endFormatToScript me
  151.   tell the stage
  152.     set scolResult to scolCommitChanges()
  153.   end tell
  154.   if scolResult = "OK" then
  155.   else
  156.     alert("Sorry, a minor error occurred:" && scolResult & RETURN & "when processing member" && the pScriptMember of me && "in castLib" && the pCastLibrary of me)
  157.   end if
  158.   tell the stage
  159.     scolReleaseCastLib()
  160.   end tell
  161.   tell the stage
  162.     scolReleaseMovie()
  163.   end tell
  164. end
  165.